package test.serverframe.armc.server.manager.dao.mapper;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import test.serverframe.armc.server.manager.domain.LinkInterface;
import test.serverframe.armc.server.manager.domain.TaskEnterInterface;
import test.serverframe.armc.server.manager.service.exec.params.InterfaceExecutorParams;

import java.util.List;
public interface TaskEnterInterfaceMapper {
    @Delete({
            "delete from tb_ssgp_task_enter_interface",
            "where task_enter_id = #{taskEnterId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String taskEnterId);

    @Insert({
            "insert into tb_ssgp_task_enter_interface (task_enter_id, node_id, ",
            "task_id, parent_ids, child_ids, interface_id)",
            "values (#{taskEnterId,jdbcType=VARCHAR}, #{nodeId,jdbcType=VARCHAR}, ",
            "#{taskId,jdbcType=VARCHAR}, #{parentIds,jdbcType=VARCHAR}, #{childIds,jdbcType=VARCHAR}, ",
            "#{interfaceId,jdbcType=VARCHAR}))"
    })
    int insert(TaskEnterInterface record);

    @InsertProvider(type = TaskEnterInterfaceSqlProvider.class, method = "insertSelective")
    int insertSelective(TaskEnterInterface record);

    @Select({
            "select",
            "task_enter_id, node_id, task_id, parent_ids, child_ids, interface_id ",
            "from tb_ssgp_task_enter_interface",
            "where task_enter_id = #{taskEnterId,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "task_enter_id", property = "taskEnterId", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "node_id", property = "nodeId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "task_id", property = "taskId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parent_ids", property = "parentIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "child_ids", property = "childIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "interface_id", property = "interfaceId", jdbcType = JdbcType.VARCHAR),

    })
    TaskEnterInterface selectByPrimaryKey(String taskEnterId);

    @Select({
            "select",
            "task_enter_id, node_id, task_id, parent_ids, child_ids, interface_id ",
            "from tb_ssgp_task_enter_interface",
            "where task_id = #{taskId,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "task_enter_id", property = "taskEnterId", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "node_id", property = "nodeId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "task_id", property = "taskId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parent_ids", property = "parentIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "child_ids", property = "childIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "interface_id", property = "interfaceId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "task_id", property = "task",
                    one = @One(
                            select = "test.serverframe.armc.server.manager.dao.mapper.TaskMapper.selectByPrimaryKey"
                    )
            )
    })
    TaskEnterInterface selectByTaskId(String taskId);

    @Select({
            "select",
            "task_enter_id, node_id, task_id, parent_ids, child_ids, interface_id ",
            "from tb_ssgp_task_enter_interface",
            "where task_id = #{taskId,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column = "task_enter_id", property = "taskEnterId", jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "node_id", property = "nodeId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "task_id", property = "taskId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "parent_ids", property = "parentIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "child_ids", property = "childIds", jdbcType = JdbcType.VARCHAR),
            @Result(column = "interface_id", property = "interfaceId", jdbcType = JdbcType.VARCHAR),
            @Result(column = "task_id", property = "task",
                    one = @One(
                            select = "test.serverframe.armc.server.manager.dao.mapper.TaskMapper.selectByPrimaryKey"
                    )
            )
    })
    List<TaskEnterInterface> selectByTaskIds(String taskid);

    @UpdateProvider(type = TaskEnterInterfaceSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TaskEnterInterface record);

    @Update({
            "update tb_ssgp_task_enter_interface",
            "set node_id = #{nodeId,jdbcType=VARCHAR},",
            "task_id = #{taskId,jdbcType=VARCHAR}",
            "where task_enter_id = #{taskEnterId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(TaskEnterInterface record);

    @Delete({
    	"delete from tb_ssgp_task_enter_interface",
        "where task_id = #{taskId,jdbcType=VARCHAR}"
    })
	void deletebyTaskId(String taskId);
    
    @Select({
    	"select node_id, parent_ids, child_ids",
        "from tb_ssgp_task_enter_interface",
        "where task_id = #{taskId,jdbcType=VARCHAR}",
    })
    @Results({
    	@Result(column = "node_id", property = "nodeId", jdbcType = JdbcType.VARCHAR),
    	@Result(column = "parent_ids", property = "parentIds", jdbcType = JdbcType.VARCHAR),
    	@Result(column = "child_ids", property = "childIds", jdbcType = JdbcType.VARCHAR),
    })
    List<TaskEnterInterface> findInterByTaskId(String taskId);
    
    @Select({
    	"select task_enter_id, node_id, task_id, parent_ids, child_ids, interface_id",
        "from tb_ssgp_task_enter_interface",
        "where task_id = #{taskId,jdbcType=VARCHAR} and node_id = #{nodeId,jdbcType=VARCHAR}",
    })
    @Results({
    	@Result(column = "task_enter_id", property = "taskEnterId", jdbcType = JdbcType.VARCHAR, id = true),
        @Result(column = "node_id", property = "nodeId", jdbcType = JdbcType.VARCHAR),
        @Result(column = "task_id", property = "taskId", jdbcType = JdbcType.VARCHAR),
        @Result(column = "parent_ids", property = "parentIds", jdbcType = JdbcType.VARCHAR),
        @Result(column = "child_ids", property = "childIds", jdbcType = JdbcType.VARCHAR),
        @Result(column = "interface_id", property = "interfaceId", jdbcType = JdbcType.VARCHAR),
    })
    TaskEnterInterface selectTaskEnterInterId(InterfaceExecutorParams params);

}